moddbfandomcom-20200213-history
Death3D
This tutorial is a simple into to Death3D. It didnt have a big huge starter tutorial before, so i made this. Currently, it's just a smash-together of the current tutorials, but this came first, so technically the other tutorials are split-offs of this. Well, who cares? we want code, right? =) The Basics Downloading First, obtain a copy of Death3D from http://death.sourceforge.net/ Your First Program Death3D is made to be simple. all you need to do to include the engine is: #include #include to include a few useful interfaces. those files will include almost everything else. Now for the good stuff. Here, we will initalise the engine: ISceneManager* smgr = new ISceneManager(); And thats it. That's how to initalise the engine. no opengl hassle, no nothing. Now, let's add a triangle scene node: ITriSceneNode* node = smgr->addTriSceneNode(); very nice. that's it! All you need to do now is simply run the engine: while(true) { smgr->RenderAll(); } and the scene manager handles the rest. Compiling Now that you've made your program, it's time to compile! Death3D uses SDL as a window manager, but this is very easy to change. But for now, let's just use SDL. Death3D uses OpenGL to render, so we must link with GL. and finally, it uses OpenGLU to setup the view & for cameras, so we must link with GLU also. g++ -o mygame mygame.cpp -lDeath3D -lSDL -lGL -lGLU and that's it. Some more advanced stuff Lighting Now, you have compiled and run your game. but, even though we added a TriSceneNode, we see nothing. This is due to multiple things: * We have no lighting * The scene node is in the screen To fix the in-the-screen problem, we can just type: node->setPosition(vector3df(0,0,80)); this puts the node to position X:0, Y:0, Z:80. Now, let's add some lighting. The lights are SO bright, that we must put the light far in front of us, to get a nice, shady look. ILightSceneNode* light = smgr->addLightSceneNode(); light->setPosition(vector3df(0,0,55)); and there you go. rerun your program to notice the nice changes =) You can also disable lighting. if lighting is disabled, lightscenenodes will be ignored and all scenenodes will be 100% lit. scenemanager->setLighting(true/false); true=on and false=off obviously. Changing the color of the light isnt hard at all: light->setRGB(r, g, b); r, g, b are each floats. 0.0f = none of that color, 1.0f = all of that color, so: light->setRGB(0.0f, 0.5f, 1.0f); would by cyan-blue, Note: Make sure the light is infront of the scene node, as that would make the light not show up on the node (obviously). Positioning, Rotating, Scaling Up until now, you've only seen a glimpse of positioning your scene node. First off, let's take a look at the vector3df type. vector3df is really nothing except a container for 3 variables: float X, float Y, float Z. these represent a position, a rotation, a scale, or any other 3-values, and SceneNodes take values in these "vectors". So, to change the rotation of our triangle, we'd type: node->setRotation(vector3df(5,5,5)); or, alternatively: vector3df MyVector(5,5,5); node->setRotation(MyVector); and, you can access vector values with: MyVector.X = 25; node->setRotation(MyVector); So, play around with vector values, and take a look at test.cpp which ships with a release download of the engine. Texturing Now that you have a nice triangle and a light, it's time to have some fun texturing your triangle. We do this by typing: node->setTexture(new CTexture("texture.raw")); we don't need to worry about CTexture, because it's a CSomething and not ISomething, so it's not an interface. all we use it for is loading a texture. .raw is a very simple format, it's just a map of pixel colors. like a bitmap, but without the headers. i'm going to write a bmp->raw converter at some point, so you can just use GIMP to turn your gif/jpg/png/etc images into BMP, and turn them into .RAW to use with the engine. Final Program You might be wondering what the final program looks like now. Here's the source: #include #include #include int main() { ISceneManager* smgr = new ISceneManager(); ITriSceneNode* node = smgr->addTriSceneNode(); node->setPosition(vector3df(0,0,80)); node->setTexture(new CTexture("texture.raw")); ILightSceneNode* light = smgr->addLightSceneNode(); light->setPosition(vector3df(0,0, 55)); while(true) { smgr->RenderAll(); } } And that's it. don't know how many lines exactly that'd be in DirectX or OpenGL, but certainly alot more than that! Thanks for visiting! Death3D Thanks for reading my tutorial, and giving death3d a chance =) If you know OpenGL and want to contribute a scenenode or some other useful stuff, please drop by the IRC Channel and see how you can help :D